package com.ruoyi.shopping.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.shopping.domain.CommodityServiceCategory;
import com.ruoyi.shopping.service.ICommodityServiceCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 服务类别管理Controller
 * 
 * @author fxy
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/shopping/serviceCategory")
public class CommodityServiceCategoryController extends BaseController
{
    @Autowired
    private ICommodityServiceCategoryService commodityServiceCategoryService;

    /**
     * 查询服务类别管理列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:serviceCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommodityServiceCategory commodityServiceCategory)
    {
        startPage();
        List<CommodityServiceCategory> list = commodityServiceCategoryService.selectCommodityServiceCategoryList(commodityServiceCategory);
        return getDataTable(list);
    }

    /**
     * 导出服务类别管理列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:serviceCategory:export')")
    @Log(title = "服务类别管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommodityServiceCategory commodityServiceCategory)
    {
        List<CommodityServiceCategory> list = commodityServiceCategoryService.selectCommodityServiceCategoryList(commodityServiceCategory);
        ExcelUtil<CommodityServiceCategory> util = new ExcelUtil<CommodityServiceCategory>(CommodityServiceCategory.class);
        util.exportExcel(response, list, "服务类别管理数据");
    }

    /**
     * 获取服务类别管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('shopping:serviceCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(commodityServiceCategoryService.selectCommodityServiceCategoryById(id));
    }

    /**
     * 新增服务类别管理
     */
    @PreAuthorize("@ss.hasPermi('shopping:serviceCategory:add')")
    @Log(title = "服务类别管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommodityServiceCategory commodityServiceCategory)
    {
        return toAjax(commodityServiceCategoryService.insertCommodityServiceCategory(commodityServiceCategory));
    }

    /**
     * 修改服务类别管理
     */
    @PreAuthorize("@ss.hasPermi('shopping:serviceCategory:edit')")
    @Log(title = "服务类别管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommodityServiceCategory commodityServiceCategory)
    {
        return toAjax(commodityServiceCategoryService.updateCommodityServiceCategory(commodityServiceCategory));
    }

    /**
     * 删除服务类别管理
     */
    @PreAuthorize("@ss.hasPermi('shopping:serviceCategory:remove')")
    @Log(title = "服务类别管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(commodityServiceCategoryService.deleteCommodityServiceCategoryByIds(ids));
    }
}
